package com.lkd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.entity.Partner;
import com.lkd.mapper.PartnerMapper;
import com.lkd.result.PageBean;
import com.lkd.service.PartnerService;
import com.lkd.vo.PartnerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class PartnerServiceImpl implements PartnerService {
    @Autowired
    private PartnerMapper partnerMapper;
    @Override
    public void save(Partner partner) {
        partner.setUpdateTime(LocalDateTime.now());
        partner.setCreateTime(LocalDateTime.now());
        partnerMapper.insert(partner);
    }

    @Override
    public PageBean<PartnerVo> findByPage(String name, Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        Page<PartnerVo> vo = partnerMapper.selectByPage(name);
        long pages =(long) vo.getPages();
        return new PageBean<PartnerVo>(pageIndex,pageSize,pages,vo.getTotal(),vo);
    }

    @Override
    public void update(Partner partner) {
        partner.setUpdateTime(LocalDateTime.now());
        partnerMapper.update(partner);
    }

    @Override
    public PartnerVo findById(Integer id) {
        PartnerVo vo = partnerMapper.findById(id);
        return vo;
    }

    @Override
    public void delete(Integer id) {
        partnerMapper.delete(id);
    }
}
